#if !defined(_RSS20_Parser_H_)
#define  _RSS20_Parser_H_

#include <iostream>
#include "rss_parser.h"
#include "Item.h"

using namespace std;

class RSS20Parser:public RSSParser
{

public:
	RSS20Parser()
	{
		/*
		* Simulate XSLT to translate each standard to intermediate DOM structure
		*/
		tag_map_["title"]="title";
		tag_map_["link"]="url";
		tag_map_["description"]="description";
		tag_map_["language"]="language";
		tag_map_["dc:language"]="language";
		tag_map_["copyright"]="copyright";
		tag_map_["dc:rights"]="copyright";
		tag_map_["category"]="category";
		tag_map_["managingEditor"]="authorEmail";
		tag_map_["author"]="authorEmail";
		tag_map_["dc:creator"]="authorEmail";
		tag_map_["guid"]="guid";
	//	tag_map_["image"]="imageUrl";
		tag_map_["pubDate"]="publishDateTime";
		tag_map_["dc:date"]="publishDateTime";
	}
	virtual ~RSS20Parser()
	{

	}

	virtual Item * ParseData(const TiXmlElement* node)
	{
		Item *itm=NULL;
		string real_tag;
		if((node->Type() == TiXmlNode::ELEMENT))
		{
			itm=new Item;

			for( const TiXmlElement* elem= node->FirstChildElement();elem;elem=elem->NextSiblingElement())
			{
				if(elem->GetText())
				{
					//cout<<elem->Value()<<"\t"<<elem->GetText()<<endl;

					/*look up the table, if not exist, we will use the original value*/
					real_tag=tag_map_[elem->Value()];
					if(real_tag.empty()||real_tag.size()==0)
						real_tag=elem->Value();

					itm->AddElem(real_tag,elem->GetText());	

				}
			}
			if(itm->getID().empty()||itm->getID().size()==0)
			{
				itm->ResetID();
			}
		}	
		return itm;
	}
};


#endif
